package com.zy.aip;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] arr = {-1,0,1,10,-3};
            InsertSort(arr);
            System.out.println("排序后的数组");
            System.out.println(Arrays.toString(arr));

    }
    public static void InsertSort(int[] arr){
        int insertVal = 0;
        int insertIndex = 0;
        for (int i = 1; i < arr.length; i++) {
            insertVal = arr[i];
            insertIndex = i - 1;
            while (insertIndex >= 0 && insertVal < arr[insertIndex]){
                arr[insertIndex + 1]=arr[insertIndex];
                insertIndex--;
            }
            arr[insertIndex+1]=insertVal;
        }
    }
}
